<template lang="jade">
h-loader-full(url='loader',:setdata='false')
  h-data-lister(data='list')
  .box
    //查询
    m-title(icon='add',name='培训题目列表')
      select(v-model='search.sid',placeholder='请选择所属培训学校')
        option(value='', selected) 请选择所属培训学校
        option(v-for='(n,i) in school', :value='n.id') {{n.name}}

    //人员信息
    table.list
      ml-header(data='题目,排序,操作')
      tr
        td 
          input(type = 'text', style="width:500px", v-model="search.question") 
        td 
        td 
          button(@click='searchdo()') 搜索

      tr(v-for='(n,i) in list')
        td(width="1200") {{ n.question }}
        td: input(type='text',v-model='n.sort')
        td
          a(href='javascript:void(0)',class='update',:data-index='i') 更新
          a(:href="'./question_edit.html?id=' + n.id") 编辑
          a(href='javascript:void(0)', @click="delete_question(n)") 删除
    .command
      button(id='update-all') 全部更新
      .page
        button( @click="pagego(1)") 首页
        button(v-show='page>1', @click="pagego('last')") 上一页
        button(v-for='(n,i) in pagearr',  @click="pagego(n)") {{n}}
        button(v-show='page < pagesnum', @click="pagego('next')") 下一页
        button( @click="pagego(pagesnum)") 末页
</template>
----------------------------------------------------------------------------------------
<script>
import { MessageBox } from 'mint-ui'
export default {
	data () {
		return {
			loader:{
        list:'get/question/list',
        school:'cultivate/school/list',
      },
      url:{
				update:'cultivate/question/sort',
			},
      list:[],
      school:[],
      page:1,
      count:0,
      pagearr:[],
      pagesnum:0,
      search:{
        question:'',
        sid:'',
      },
		}
	},
  mounted () {
    
  },
  watch:{
    pagesnum:function(val){
      console.log(val)
    },
  },
	methods: {
		loadAfter(data){
      this.list=data.list.list[0]
      this.school = data.school[0]

      this.count=data.list.count
      this.page=data.list.page
      this.pagesnum=data.list.pagesnum
      for(var i=1; i<=data.list.pagesnum; i++){
        this.pagearr.push(i);
      }
		},
    updateAfter (res) {
		},
    // 分页
    pagego (type) {
      if(type == "last"){
        this.page = this.page - 1;
      }else
      if(type == "next"){
        this.page = this.page + 1;
      }else{
        this.page = type
      }

      this.$ajax.get('get/question/list' + '?page=' + this.page + "&question=" + this.search.question + "&sid=" + this.search.sid, (res) => {
        this.list = res.data.list[0]
      }, (res) => {
        this.error(res.message)
      })
    },
    //删除
    delete_question(n){
      if(confirm("确定要删除,删除后相关数据将无法恢复")){
        this.$ajax.delete("cultivate/delete/question?id="+n.id, (res)=>{
          this.$msg.success(res.message);
          window.location.href = window.location.href;
        }, (res)=>{
          this.$msg.error(res.message);
        })
      }
    },

    searchdo(){
      this.$ajax.get('get/question/list' + "?question=" + this.search.question + "&sid=" + this.search.sid, (res) => {
        this.list = res.data.list[0]
        this.count=res.data.count
        this.page=res.data.page
        this.pagesnum=res.data.pagesnum
        let pagearr = [];
        for(var i=1; i<=res.data.pagesnum; i++){
          pagearr.push(i);
        }
        this.pagearr = pagearr;
      }, (res) => {
        this.error(res.message)
      })
    },

	}
}
</script>
----------------------------------------------------------------------------------------
<style lang="less" scoped>
@import "../../../plugin/style/mixin";
.page{ float:right; }
  .page a{background: #4db3ff; color: #fff; padding:3px 10px; border-radius:4px; cursor:pointer;}
  .page b{margin:0 10px;}
</style>